/**
 * SimpleControler Class
 * (C) copyright 2006-2007 geolabs
 * author: Gérald Fenoy gerald [ at ] geolabs [dot] fr
 *
 */      
MapLayerControler=Controler.extend();

MapLayerControler.define({

  _init: function(loading_image,map_image,opacity){
      this.content=document.getElementById(map_image);
      this.loading=document.getElementById(loading_image);
      this.status=document.getElementById("statusText");
      this.time=document.getElementById("timelog");
      this.fade=opacity?opacity:95;
    },

      setContent: function(){
      this.content.src=arguments[0];
    },

      setTime: function(){
      this.time.innerHTML=arguments[0];
    },

  setForm: function(){
      document.myform.minx.value=arguments[0].minx;
      document.myform.miny.value=arguments[0].miny;
      document.myform.maxx.value=arguments[0].maxx;
      document.myform.maxy.value=arguments[0].maxy;
    },

  reinitFade: function(){
      //this.fade=10;
    },

  displayStatus: function(){
      this.loading.style.display="inline";
      //alert("call super displayStatus - before ");
      this.superCall("displayStatus",arguments);
      //alert("call super displayStatus - after ");
      Styler.setOpacity(this.loading,this.fade);
    },

  newData: function(){
      try{
	// View update
	this.displayStatus("Displaying");
	var tmp=new XmlToJson({xml:this.request.responseXML, root: "result", loop: "item"});
	tmp.createTree();

	//this.tree=tmp.tree;
	
	this.setContent(tmp.tree.result.image_url);
	this.setTime(tmp.tree.result.time);
	this.setForm(tmp.tree.result.extent);

	if(tmp.tree.result.stat)
	  document.getElementById('output').parentNode.style.display='block';
	else
	  document.getElementById('output').parentNode.style.display='none';

	var toto=document.getElementById("fichier");	
	if(tmp.tree.result.document){
	  toto.href=tmp.tree.result.document;
	  document.getElementById('fichier_ext').src="./images/"+tmp.tree.result.document_ext+".png";
	  Effect.slide({start:1,end:10,iwidth:100,height:40,id:"fichier"});
	  toto.parentNode.style.display='block';
	  //document.getElementById("docview").src=tmp.tree.result.document;
	  //alert(tmp.tree.result.document);
	}
	else{
	  toto.parentNode.style.display='none';
	}
	if(tmp.tree.result.legend_url){
	  //alert(document.getElementById('legend'));
	  document.getElementById('legend').parentNode.style.display='block';
	  //alert(document.getElementById('legend').parentNode.style.display);
	  document.getElementById('legend').src=tmp.tree.result.legend_url+"";
	  //alert(document.getElementById('legend')+" "+document.getElementById('legend').src);
	}
	else document.getElementById('legend').parentNode.style.display='none';

	/*if(tmp.tree.result.document){
	  document.getElementById("docview").src=tmp.tree.result.document;
	  document.getElementById("docview").style.display='block'
	}
	else document.getElementById("docview").style.display='none';*/

	Styler.setOpacity(this.loading,10);
	Styler.setOpacity(this.content,0);

	Effect.appear({id: this.content.id,start:0,limit:10});
	Effect.fade({id: this.loading.id,start:0,limit:6});
	setTimeout("document.getElementById('"+this.loading.id+"').style.display='none'",2000);

	this.isSegmentActive=(document.getElementById('CMD').value=="segmentize");
	//alert(this.isSegmentActive);

	/*if(tmp.tree.result.haspath==1)
	  document.getElementById("options_content").style.display="block";
	else
	document.getElementById("options_content").style.display="none";*/

      }
      catch(e) {
	this.status.innerHTML="There was a problem parsing the XML data:\n" +this.request.statusText+" "+e;
      }
      this.request=null;
    }
  });
